$(document).ready(function() {
	$('#flot-graph').bind('plothover', function (event, pos, item) {
			$("#x").text(pos.x.toFixed(2));
        	$("#y").text(pos.y.toFixed(2));
            if (item) {
                if (previousPoint != item.datapoint) {
                    var xDate = new Date();
                    previousPoint = item.datapoint;
                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2), y = item.datapoint[1].toFixed(2);
                    showTooltip(item.pageX, item.pageY, Math.round(y) + " " + item.series.label +" errors on " +
                     xDate.getMonth(x) +'/'+ xDate.getDate(x) + '/' + xDate.getFullYear(x));
                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
		});
});

function showTooltip(x, y, contents) {
        $('<div id="tooltip">' + contents + '</div>').css( {
            position: 'absolute',
            display: 'none',
            top: y - 35,
            left: x + 5,
            border: '1px solid #fdd',
            padding: '2px',
            'background-color': '#fee',
            opacity: 0.80
        }).appendTo("body").fadeIn(200);
    }